<!--link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl.WWWROOT_BACKEND; ?>/css/form.css"/>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl.WWWROOT_BACKEND; ?>/js/jquery.min.js">	</script-->

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'news-entries-form',
	'enableClientValidation'=>true,
    'htmlOptions'=>array('enctype'=>'multipart/form-data', 'class'=>'form-horizontal'),
)); ?>
	<fieldset>
	<p class="note">Fields with <span class="required">*</span> are required.</p>
	<div class="control-group">
		<?php echo $form->labelEx($model,'name', array('class'=>'control-label')); ?>
		<div class="controls">
		<?php echo $form->textField($model,'name',array('size'=>30)); ?>
		<?php echo $form->error($model,'name'); ?>
        <script type="text/javascript" language="javascript">
            jQuery(document).ready(function() {
                $('#Products_name').keyup(function(){
                    createAlias();
                });
                $('#Products_name').focusout(function(){
                    createAlias();
                });
								
				function createAlias() {
                    var value = $('#Products_name').val();
                    value = value.replace(/[áàảãạăắằẳẵặâấầẩẫậ]/ig, 'a');
                    value = value.replace(/[đ]/ig, 'd');
                    value = value.replace(/[éèẻẽẹêếềểễệ]/ig, 'e');
                    value = value.replace(/[íìỉĩị]/ig, 'i');
                    value = value.replace(/[óòỏõọôốồổỗộơớờởỡợ]/ig, 'o');
                    value = value.replace(/[úùủũụưứừửữự]/ig, 'u');
                    value = value.replace(/[ýỳỷỹỵ]/ig, 'y');
                    value = value.replace(/[^A-Za-z0-9\s_-]/ig, '');
                    value = value.replace(/\s/ig, '-');
                    value = value.toLowerCase();
                    $('#Products_alias').val(value);
                };
            });
        </script>
		</div>
	</div>

	<div class="control-group">
		<?php echo $form->labelEx($model,'alias', array('class'=>'control-label')); ?>
		<div class="controls">
		<?php echo $form->textField($model,'alias',array('size'=>30)); ?>
		<?php echo $form->error($model,'alias'); ?>
		</div>
	</div>
	
	<?php if(Yii::app()->controller->module->price['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'price', array('class'=>'control-label')); ?>
		<div class="controls">
		<?php echo $form->textField($model,'price',array('size'=>30)); ?>
		<?php echo $form->error($model,'price'); ?>
		</div>
	</div>
	<?php } ?>
	
	<?php if(Yii::app()->controller->module->special_price['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'special_price', array('class'=>'control-label')); ?>
		<div class="controls">
		<?php echo $form->textField($model,'special_price',array('size'=>30)); ?>
		<?php echo $form->error($model,'special_price'); ?>
		</div>
	</div>
	<?php } ?>
	
	<?php if(Yii::app()->controller->module->style['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'style', array('class'=>'control-label')); ?>
		<div class="controls">
		<?php echo $form->textField($model,'style',array('size'=>30)); ?>
		<?php echo $form->error($model,'style'); ?>
		</div>
	</div>
	<?php } ?>
	
	<?php if(Yii::app()->controller->module->quantity['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'quantity', array('class'=>'control-label')); ?>
		<div class="controls">
		<?php echo $form->textField($model,'quantity',array('size'=>30)); ?>
		<?php echo $form->error($model,'quantity'); ?>
		</div>
	</div>
	<?php } ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'categories', array('class'=>'control-label')); ?>
		<div class="controls list-categories">
		<input id="ProductMiddle_category_id" type="hidden" value="" name="ProductMiddle[category_id]" />
		<?php
		foreach ($modelCategories as $index => $cat){
			$checked = '';
			if(isset($catIdsBelongTo)){
				if(in_array($cat->id, $catIdsBelongTo)){
					$checked = 'checked="checked"';
				}
			}
			
		?>
		<input <?php echo $checked?> id="ProductMiddle_category_id_<?php echo $index; ?>" value="<?php echo $cat->id; ?>" type="checkbox" name="ProductMiddle[category_id][]" /> 
				<label for="ProductMiddle_category_id_<?php echo $index; ?>"><?php echo $cat->name; ?></label>
		<?php } ?>
		<?php echo $form->error($model,'categories'); ?>
		</div>
	</div>
	
	<?php if(Yii::app()->controller->module->image['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'image', array('class'=>'control-label')); ?>
		<div class="controls">
		<div class="image-form">
		<?php if (isset($model->image) && ($model->image != 'NULL')): ?>
			<?php 
			if(file_exists(YiiBase::getPathOfAlias('webroot').$this->module->image['url']. $model->image)): ?>
				<img src="<?php echo  $this->module->image['url'] . $model->image; ?>" width="100" height="70"/>
			<?php else : ?>
				<?php echo CHtml::image($this->module->image['url'].'no-image.png', 'Image', array(
							'width'		=>	'100',
							'height'	=>	'70'
				)); ?>
			<?php endif ?>
			<div class="clr"></div>
		<?php endif ?>
		<?php echo $form->fileField($model,'image'); ?>
		</div>
		<?php echo $form->error($model,'image'); ?>
		</div>
	</div>
	<?php } ?>

	<?php if(Yii::app()->controller->module->catalog_image['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'catalog_image', array('class'=>'control-label')); ?>
		<div class="controls">
		<div class="image-form">
		<?php if (isset($model->catalog_image) && ($model->image != 'NULL')): ?>
			<?php 
			if(file_exists(YiiBase::getPathOfAlias('webroot').$this->module->catalog_image['url']. $model->catalog_image)): ?>
				<img src="<?php echo  $this->module->catalog_image['url'] . $model->catalog_image; ?>" width="100" height="70"/>
			<?php else : ?>
				<?php echo CHtml::image($this->module->catalog_image['url'].'no-image.png', 'Image', array(
							'width'		=>	'100',
							'height'	=>	'70'
				)); ?>
			<?php endif ?>
			<div class="clr"></div>
		<?php endif ?>
		<?php echo $form->fileField($model,'catalog_image'); ?>
		</div>
		<?php echo $form->error($model,'catalog_image'); ?>
		</div>
	</div>
	<?php } ?>

	<?php if(Yii::app()->controller->module->description['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'description', array('class'=>'control-label')); ?>
		<div class="controls">
		<div class="ckeditor">
			<?php $this->widget('application.extensions.ckeditor.CKEditor', array(
				'model'=>$model,
				'attribute'=>'description',
				'language'=>'en',
				'editorTemplate'=>'advanced',
				'width'	=>	'620px',
				'height'	=>	'420px',
				'options'=>array(
					'filebrowserUploadUrl'=>$this->createUrl('upload'),
				),
				//'rows'=>10, 
				//'cols'=>30,
				'toolbar'=>array(
					array('Bold', 'Italic', 'Underline', 'Strike'),
					array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'),
					array('Format'),
					array( 'Font', 'FontSize', 'FontColor', 'TextColor'),
					'/',
					array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord' ),
					array('Image', 'Table', 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'),
					array('Subscript','Superscript'),
					array( 'Link', 'Unlink' ),
					array('Source')
				)
				)); 
			?>
		</div>
		<?php echo $form->error($model,'description'); ?>
		</div>
	</div>
	<?php } ?>

	<?php if(Yii::app()->controller->module->content['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'content', array('class'=>'control-label')); ?>
		<div class="controls">
		<div class="ckeditor">
			<?php $this->widget('application.extensions.ckeditor.CKEditor', array(
				'model'=>$model,
				'attribute'=>'content',
				'language'=>'en',
				'editorTemplate'=>'advanced',
				'width'	=>	'620px',
				'height'	=>	'420px',
				'options'=>array(
					'filebrowserUploadUrl'=>$this->createUrl('upload'),
				),
				//'rows'=>10, 
				//'cols'=>30,
				'toolbar'=>array(
					array('Bold', 'Italic', 'Underline', 'Strike'),
					array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'),
					array('Format'),
					array( 'Font', 'FontSize', 'FontColor', 'TextColor'),
					'/',
					array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord' ),
					array('Image', 'Table', 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'),
					array('Subscript','Superscript'),
					array( 'Link', 'Unlink' ),
					array('Source'),
				)
				)); 
			?>
		</div>
		<?php echo $form->error($model,'content'); ?>
		</div>
	</div>
	<?php } ?>
    
	<?php if(Yii::app()->controller->module->product_date['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'product_date', array('class'=>'control-label')); ?>
		<div class="controls">
			<?php
					$this->widget('zii.widgets.jui.CJuiDatePicker', array(
							'model' => $model,
							'attribute' => 'n_date',
							'htmlOptions' => array('readonly' => "readonly")   
					));
			?>
			<?php echo $form->textField($model,'n_hours',array('size'=>3,'maxlength'=>2)); ?>
			<?php echo $form->textField($model,'n_minutes',array('size'=>3,'maxlength'=>2)); ?>
			<?php echo $form->error($model,'product_date'); ?>
			<?php echo $form->error($model,'n_hours'); ?>
			<?php echo $form->error($model,'n_minutes'); ?>
		</div>
	</div>
	<?php } ?>

	<div class="control-group">
		<?php echo $form->labelEx($model,'is_published', array('class'=>'control-label')); ?>
		<div class="controls">
		<?php echo $form->checkBox($model,'is_published'); ?>
		<?php echo $form->error($model,'is_published'); ?>
		</div>
	</div>

	<?php if(Yii::app()->controller->module->is_special['show']) { ?>
	<div class="control-group">
		<?php echo $form->labelEx($model,'is_special', array('class'=>'control-label')); ?>
		<div class="controls">
		<?php echo $form->checkBox($model,'is_special'); ?>
		<?php echo $form->error($model,'is_special'); ?>
		</div>
	</div>
	<?php } ?>
    
	<div class="form-actions">
        <a class='btn btn-primary' href="<?php echo Yii::app()->createUrl("/products/manage_product/admin"); ?>">Cancel</a>
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class'=>'btn btn-primary')); ?>
	</div>
	</fieldset>

<?php $this->endWidget(); ?>

<script>
  $(function () {
	$('#Products_style').manifest({valuesName:"Products[itemStyle]"});
	$('.mf_container').append('<a class="addStyle" href="javascript:void(0);"> Add style</a>')
  });
</script>